package com.enlf.interceptor;

import com.enlf.utils.UserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * _*_ coding : utf-8 _*_
 *
 * @Time : 2023/9/12 14:20
 * @Author : 计201任思伟
 * @File : LoginInterceptor
 * @Project : enjoy-life
 */
public class LoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从ThreadLocal中获取用户,如果没有就拦截
        if(UserHolder.getUser() == null){
            response.setStatus(401);
            return false;
        }
        //有用户放行
        return true;
    }


}
